package cn.yuanqiao.web.controller.archive.statistics;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.appManager.service.IYqdaTreesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.statistics.domain.StatisticalConfiguration;
import cn.yuanqiao.archive.statistics.service.IStatisticalConfigurationService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 年报统计配置Controller
 * 
 * @author xy
 * @date 2023-07-31
 */
@RestController
@RequestMapping("/archive/StatisticalConfiguration")
public class StatisticalConfigurationController extends BaseController
{
    @Autowired
    private IStatisticalConfigurationService statisticalConfigurationService;

    @Autowired
    private IYqdaTreesService yqdaTreesService;

    /**
     * 查询年报统计配置列表
     */
//    @RequiresPermissions("archive:StatisticalConfiguration:list")
    @GetMapping("/list")
    public TableDataInfo list(StatisticalConfiguration statisticalConfiguration)
    {
        startPage();
        List<StatisticalConfiguration> list = statisticalConfigurationService.selectStatisticalConfigurationList(statisticalConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出年报统计配置列表
     */
//    @RequiresPermissions("archive:StatisticalConfiguration:export")
    @Log(title = "年报统计配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StatisticalConfiguration statisticalConfiguration)
    {
        List<StatisticalConfiguration> list = statisticalConfigurationService.selectStatisticalConfigurationList(statisticalConfiguration);
        ExcelUtil<StatisticalConfiguration> util = new ExcelUtil<StatisticalConfiguration>(StatisticalConfiguration.class);
        util.exportExcel(response, list, "年报统计配置数据");
    }

    /**
     * 获取年报统计配置详细信息
     */
    /* @RequiresPermissions("archive:StatisticalConfiguration:query")*/
    @GetMapping("/{type}")
    public AjaxResult getInfo(@PathVariable("type")String type)
    {
        Long id=0L;
        return success(statisticalConfigurationService.selectStatisticalConfigurationById(id,type));
    }

    /**
     * 新增年报统计配置
     */
/*
    @RequiresPermissions("archive:StatisticalConfiguration:add")
*/
//    @RequiresPermissions("archive:statistics:statisticalConfiguration:add")
    @Log(title = "年报统计配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StatisticalConfiguration statisticalConfiguration)
    {
        return toAjax(statisticalConfigurationService.insertStatisticalConfiguration(statisticalConfiguration));
    }

    /**
     * 修改年报统计配置
     */
//    @RequiresPermissions("archive:StatisticalConfiguration:edit")
    @Log(title = "年报统计配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StatisticalConfiguration statisticalConfiguration)
    {
        return toAjax(statisticalConfigurationService.updateStatisticalConfiguration(statisticalConfiguration));
    }

    /**
     * 删除年报统计配置
     */
//    @RequiresPermissions("archive:StatisticalConfiguration:remove")
    @Log(title = "年报统计配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(statisticalConfigurationService.deleteStatisticalConfigurationByIds(ids));
    }
    @GetMapping("/gettrees")
    public AjaxResult getcatemodeltree(){
        return success(yqdaTreesService.getAllTreeList());
    }
}
